/**
 * Created by Administrator on 2017/5/20 0020.
 */
$(function(){
   //  //懒加载
    $(".lazy").lazyload();
    //北京地址
    //限时优惠
   $("#btn_buy").on("click",function(){
       window.location.href="/shanmao/index/detail.html";
   })
    //


   //banner图 实现
    // 存放背景图片地址
    var num=0;
    var flag = true;//控制一次转换才切换下一张
    var obj = new Object();//定时器返回值
    var arr=["url(images/banner1.jpg)","url(images/banner2.jpg)","url(images/banner3.jpg)"];
    function toggleImg(num,fn){
        $(".banner").css("background",arr[num]);
        $(".spans").find("span").eq(num).css("background","orange").siblings("span").css("background","#fff");

        if(fn!=null){
               console.log(1);
               fn();
           }
    }
    //自动播放
    obj.timer =  setInterval(time,2000);
    function time(){
       toggleImg(num);
        num++;
        if(num==3){
            num=0;
        }
    }
    //方向箭头右
    $(".next").on({
        click:function(){
            if(flag==true){
                flag=false;
                num++;
                //到最后一张 切换到第一张
                if(num==3) {
                    num=0;
                }
            }
            toggleImg(num,function(){
                flag=true;
            });
        }
    });
    //方向箭头左
    $(".pre").on({
        click:function(){
            if(flag==true){
                flag=false;
                num--;
                if(num==-1) {
                    num=2;
                }
            }
            toggleImg(num,function(){flag=true});
        }
    })
    $(".spans").find("span").each(function(index,ele){
        $(ele).mouseenter(function(){
            clearInterval(obj.timer);
            toggleImg(index);

        })
    })
//暂停  启动 定时器
    $(".pre").on({
        mouseenter:function(){
            clearInterval(obj.timer);
        },
        mouseleave:function(){
            obj.timer=setInterval(time,2000);
        }
    })
    $(".next").on({
        mouseenter:function(){
            clearInterval(obj.timer);
        },
        mouseleave:function(){
            obj.timer=setInterval(time,2000);
        }
    })
    $(".spans").find("span").each(function(index,ele){
        $(ele).mouseenter(function(){

        })
        $(ele).mouseleave(function(){
            obj.timer=setInterval(time,2000);
        })
    })
//菜单显示
    $("#catalog>ul>li").each(function(index,ele){
        $(ele).hover(function(){
            $(".business").children("div").eq(index).show();
        },function(){

            $(".business").children("div").eq(index).hide();
        })
    })
//客户声音 轮播图 模块
    //自动轮播
    var num = 1;
    function bn2broad(){
        var left = $("#boss_info").offset().left;
        if(parseInt(left)>0){
            $("#boss_info").animate({"left":-1180*1},1000);
        }
        if(parseInt(left)<0){
            $("#boss_info").animate({"left":-1180*0},1000);
        }
        }

    setInterval(bn2broad,2000);
    //往左
    $(".c-prev").on("click",function(){
        var left = $("#boss_info").offset().left;

        if(parseInt(left)>0){
            $("#boss_info").animate({"left":-1180*1},"slow");
        }
        if(parseInt(left)<0){
            $("#boss_info").animate({"left":-1180*0},"slow");
        }
    });
    //往右
    $(".c-next").on("click",function(){
        var left = $("#boss_info").offset().left;
        if(parseInt(left)>0){
            $("#boss_info").animate({"left":-1180},"slow");
        }
        if(parseInt(left)<0){
            $("#boss_info").animate({"left":0},"slow");
        }
    })
    //图片转换
    $(".customer-content").children("ul").children("li").each(function(index,ele){
        $(ele).mouseover(function(){
            var i=index+1;
            $(this).find("img").attr("src","images/lx_kehu_"+i+"_2.png");
        });
        $(ele).mouseleave(function(){
            var i=index+1;
            $(this).find("img").attr("src","images/lx_kehu_"+i+".png");
        });
    })
})
